package com.bkgy.modular.tbdecsionrule.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bkgy.modular.tbdecsionrule.dto.TbDsjHourProductionDto;
import com.bkgy.modular.tbdecsionrule.dto.TbDsjPlancheckThresholdDto;
import com.bkgy.modular.tbdecsionrule.service.TbDecsionRuleService;
import com.bkgy.modular.tbdecsionrule.service.TbDsjHourProductionService;
import com.bkgy.modular.tbdecsionrule.service.TbDsjPlancheckThresholdService;
import com.bkgy.sys.common.entity.JCommon;
import com.bkgy.sys.common.entity.ResultData;
import com.bkgy.util.CodiUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/tbDecsionRule")
public class TbDecsionRuleController {
    @Resource
    private TbDecsionRuleService tbDecsionRuleService;

    @Resource
    private TbDsjHourProductionService tbDsjHourProductionService;

    @Resource
    private TbDsjPlancheckThresholdService tbDsjPlancheckThresholdService;

    /**
     * 添加记录
     *
     * @param data userId 用户id
     * @param data sname 用户姓名
     */
    @CrossOrigin
//    @RequestMapping(value = {"/insertOne"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData insertOne(@RequestBody String data, @RequestHeader(value = "loginToken") String loginToken) {
        JCommon common = JSON.parseObject(loginToken, JCommon.class);
        String sname = common.getSname();
        Long userId = common.getUserId();
        return tbDecsionRuleService.insertOne(data, userId, CodiUtil.returnLm(sname));
    }


    /**
     * 根据主键删除对象
     *
     * @param data json字符串
     */
    @CrossOrigin
//    @RequestMapping(value = {"/deleteOneById"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData deleteOneById(@RequestBody String data) {
        return tbDecsionRuleService.deleteOneById(data);
    }


    /**
     * 根据主键字符串删除多个对象
     * @param data json字符串ID数组
     */
    @CrossOrigin
//    @RequestMapping(value = {"/deleteManyByIds"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData deleteManyByIds(@RequestBody String data) {
        return tbDecsionRuleService.deleteManyByIds(data);
    }


    /**
     * 修改记录
     * @param data json字符串
     * @param loginToken 请求头参数字符串对象
     */
    /*@CrossOrigin
    @RequestMapping(value={"/update"}, method=RequestMethod.POST)
    @ResponseBody
    public ResultData updateDataTbDecsionRule(@RequestBody String data,@RequestHeader(value="loginToken") String loginToken){
        JCommon common = JSON.parseObject(loginToken,JCommon.class);
        String sname = common.getSname();
        Long userId = common.getUserId();
        return tbDecsionRuleService.updateDataTbDecsionRule(data,userId,CodiUtil.returnLm(sname));
    }*/

    @CrossOrigin
    @RequestMapping(value={"/update"}, method=RequestMethod.POST)
    @ResponseBody
    public ResultData updateDataTbDecsionRule(@RequestBody JSONObject jsonObject){
        return tbDecsionRuleService.updateDataTbDecsionRule(jsonObject);
    }

    /**
     * 分页查看记录
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/findByPage"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findDataTbDecsionRuleByPage(@RequestBody String data) {
        return tbDecsionRuleService.findDataTbDecsionRuleByPage(data);
    }


    @PostMapping("/findProductionData")
    public ResultData findProductionData(@RequestBody JSONObject jsonObject) {
        return tbDsjHourProductionService.findProductionData(jsonObject);
    }

    @PostMapping("/updateProductionData")
    public ResultData updateProductionData(@RequestBody TbDsjHourProductionDto tbDsjHourProductionDto) {
        return tbDsjHourProductionService.updateProductionData(tbDsjHourProductionDto);
    }

    @PostMapping("/findPlanCheckThrsholdData")
    public ResultData findPlanCheckThrsholdData(@RequestBody JSONObject jsonObject) {
        return tbDsjPlancheckThresholdService.findPlanCheckThrsholdData(jsonObject);
    }

    @PostMapping("/updatePlanCheckThrsholdData")
    public ResultData updatePlanCheckThrsholdData(@RequestBody TbDsjPlancheckThresholdDto tbDsjPlancheckThresholdDto) {
        return tbDsjPlancheckThresholdService.updatePlanCheckThrsholdData(tbDsjPlancheckThresholdDto);
    }

    @PostMapping("/exportXlsx")
    public void exportList(@RequestBody JSONObject jsonObject, HttpServletResponse response) {
        tbDecsionRuleService.exportList(jsonObject,response);
    }
}
